package com.pti.usermanager.web.controller;


import com.pti.usermanager.service.api.MenuService;
import com.pti.usermanager.web.dto.request.SaveMenuRequest;
import com.pti.usermanager.web.dto.request.UpdateMenuRequest;
import com.pti.usermanager.web.dto.response.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName: MenuController
 * @Author: liuyueyang
 * @Description: 菜单控制层
 * @Date: 2019/1/18
 */
@RestController
@Api(value = "菜单管理接口", tags = "提供菜单的管理接口")
public class MenuController {

    private static final Logger logger = LogManager.getLogger(MenuController.class);

    @Autowired
    private MenuService menuService;

    @GetMapping("/menu/getMenuTree")
    @ApiOperation(value = "获取岗位树结构", notes = "获取岗位树结构", produces = "application/json")
    public ResultResponse getPostTree() {
        return menuService.findTreeByMenu();
    }

    @PostMapping("/menu/saveMenu")
    @ApiOperation(value = "添加菜单列表", notes = "添加菜单列表", produces = "application/json")
    public ResultResponse saveUser(@RequestBody SaveMenuRequest saveMenuRequest) {
        return menuService.saveMenu(saveMenuRequest);
    }

    @PutMapping("/menu/updateMenu")
    @ApiOperation(value = "修改菜单列表", notes = "修改菜单列表", produces = "application/json")
    public ResultResponse updateUser(@RequestBody UpdateMenuRequest updateMenuRequest) {
        return menuService.updateMenu(updateMenuRequest);
    }

    @DeleteMapping("/menu/delMenu/{menuId}")
    @ApiOperation(value = "删除菜单", notes = "删除菜单", produces = "application/json")
    public ResultResponse delMenu(@PathVariable(value = "menuId") Long menuId) {
        return menuService.delMenu(menuId);
    }


    @GetMapping("/menu/allMenu")
    @ApiOperation(value = "all菜单", notes = "all菜单", produces = "application/json")
    public ResultResponse findAallList(@RequestParam(value = "menuNm", required = false) String menuNm) {
        return menuService.findAll(menuNm);
    }

    @GetMapping("/menu/menuDetail/{menuId}")
    @ApiOperation(value = "菜单详情", notes = "菜单详情", produces = "application/json")
    public ResultResponse findAllByPostId(@PathVariable("menuId") Long menuId) {
        return menuService.findAllByMenuId(menuId);
    }

    @GetMapping("/menu/menuDetailByUsrId/{usrId}")
    @ApiOperation(value = "根据用户ID查询菜单详情", notes = "根据用户ID查询菜单详情", produces = "application/json")
    public ResultResponse findAllByUsrId(@PathVariable("usrId") Long usrId) {
        return menuService.findAllByUsrId(usrId);
    }

}
